home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / errmsg.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  7KB  |  272 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9.  
  10. #include "hdr.h"
  11. #include "ada.h"
  12. #include "hdr.h"
  13. #include "vars.h"
  14. #include "miscp.h"
  15. #include "chapp.h"
  16. #include "smiscp.h"
  17. #include "sspansp.h"
  18. #include "errmsgp.h"
  19.  
  20. static char *strings[5];
  21.  
  22. static char *insert(char *, int);
  23.  
  24. void errmsg(char *msg, char *lrm_sec, Node node)                /*;errmsg*/
  25. {
  26.     /* Semantic errors */
  27.  
  28.     int begline, begcol, endline, endcol;
  29.     Span lspan, rspan;
  30.  
  31.     if (cdebug2 > 3) TO_ERRFILE("AT PROC : errmsg(msg, lrm_sec, node); ");
  32.  
  33.     if (node == OPT_NODE) node = current_node;
  34.     if (node != (Node)0) {
  35.         lspan = get_left_span(node);
  36.         rspan = get_right_span(node);
  37.         begline = lspan->line;
  38.         begcol    = lspan->col;
  39.         endline = rspan->line;
  40.         endcol    = rspan->col;
  41.     }
  42.     else 
  43.         /* this is in case rcv null node - put message at beginning of file*/
  44.         /* only temp-eventually, all calls to errmsg should have valid node */
  45.         begline = begcol = endline = endcol = 1;
  46.  
  47.     fprintf(msgfile, "%d %d %d %d %d\t%s", ERR_SEMANTIC, begline, begcol,
  48.       endline, endcol, msg);
  49.     if (!streq(lrm_sec, "none"))
  50.         fprintf(msgfile, " (RM %s)", lrm_sec);
  51.     fprintf(msgfile, "\n");
  52.     errors = TRUE;
  53. }
  54.  
  55. void warning(char *msg, Node node)                                /*;warning*/
  56. {
  57.     int begline, begcol, endline, endcol;
  58.     Span lspan, rspan;
  59.  
  60.     if (cdebug2 > 3) TO_ERRFILE("AT PROC : warning(msg);");
  61.  
  62.     if (node == OPT_NODE) node = current_node;
  63.     if (node != (Node)0) {
  64.         lspan = get_left_span(node);
  65.         rspan = get_right_span(node);
  66.         begline = lspan->line;
  67.         begcol    = lspan->col;
  68.         endline = rspan->line;
  69.         endcol    = rspan->col;
  70.     }
  71.     else 
  72.         /* this is in case rcv null node - put message at beginning of file*/
  73.         /* only temp-eventually, all calls to errmsg should have valid node */
  74.         begline = begcol = endline = endcol = 1;
  75.  
  76.     fprintf(msgfile, "%d %d %d %d %d\t%s", ERR_WARNING, begline, begcol,
  77.       endline, endcol, msg);
  78.     fprintf(msgfile, "\n");
  79. }
  80.  
  81.  
  82. void errmsg_id(char *msg, Symbol name, char *lrm, Node node)    /*;errmsg_id*/
  83. {
  84.     strings[0] = ORIG_NAME(name);
  85.     errmsg(insert(msg, 1), lrm, node);
  86. }
  87.  
  88. void errmsg_str(char *msg, char *str, char *lrm, Node node)        /*;errmsg_str*/
  89. {
  90.     strings[0] = str;
  91.     errmsg(insert(msg, 1), lrm, node);
  92. }
  93.  
  94. void errmsg_nat(char *msg, Symbol sym, char *lrm, Node node)    /*;errmsg_nat*/
  95. {
  96.     strings[0] = nature_str(NATURE(sym));
  97.     errmsg(insert(msg, 1), lrm, node);
  98. }
  99.  
  100. void errmsg_type(char *msg, Symbol type, char *lrm, Node node)    /*;errmsg_type*/
  101. {
  102.     strings[0] = full_type_name(type);
  103.     errmsg(insert(msg, 1), lrm, node);
  104. }
  105.  
  106. void errmsg_nval(char *msg, Node name, char *lrm, Node node)    /*;errmsg_nval*/
  107. {
  108.     strings[0] = N_VAL(name);
  109.     errmsg(insert(msg, 1), lrm, node);
  110. }
  111.  
  112. void errmsg_id_id(char *msg, Symbol name1, Symbol name2, char *lrm, Node node)
  113.                                                             /*;errmsg_id_id*/
  114. {
  115.     strings[0]     = ORIG_NAME(name1);
  116.     strings[1] = ORIG_NAME(name2);
  117.     errmsg(insert(msg, 2), lrm, node);
  118. }
  119.  
  120. void errmsg_id_type(char *msg, Symbol name, Symbol type, char *lrm, Node node)
  121.                                                             /*;errmsg_id_type*/
  122. {
  123.     strings[0]     = ORIG_NAME(name);
  124.     strings[1] = full_type_name(type);
  125.     errmsg(insert(msg, 2), lrm, node);
  126. }
  127.  
  128. void errmsg_nat_id_str(char *msg, Symbol sym, Symbol name, char *str, char *lrm,
  129.   Node node)                                            /*;errmsg_nat_id_str*/
  130. {
  131.     char *name_str;
  132.  
  133.     strings[0] = nature_str(NATURE(sym));
  134.     name_str = ORIG_NAME(name);
  135.     if (name_str[0] == '#') name_str = "#BLOCK";
  136.     strings[1] = name_str;
  137.     strings[2] = str;
  138.  
  139.     errmsg(insert(msg, 3), lrm, node);
  140. }
  141.  
  142. void errmsg_str_id(char *msg, char *str, Symbol name, char *lrm, Node node)
  143.                                                             /*;errmsg_str_id*/
  144. {
  145.     strings[0]     = str;
  146.     strings[1] = ORIG_NAME(name);
  147.     errmsg(insert(msg, 2), lrm, node);
  148. }
  149.  
  150. void errmsg_str_num(char *msg, char *str, int i, char *lrm, Node node)
  151.                                                         /*;errmsg_str_num*/
  152. {
  153.     char numstr[5];
  154.  
  155.     strings[0] = str;
  156.     sprintf(numstr, "%d", i);
  157.     strings[1] = numstr;
  158.  
  159.     errmsg(insert(msg, 2), lrm, node);
  160. }
  161.  
  162. static char *insert(char *in_format, int nstrings)                /*;insert*/
  163. {
  164.     /*  -in_format- is a character string containing an error message, and 1 or
  165.      *  more "substitution" (%) characters to be replaced by the character
  166.      *  strings pointed to by the array -strings-
  167.      *  -tmp_format- is a working copy to be used by this procedure (to avoid
  168.      *  "clobbering" string constants).
  169.      */
  170.  
  171.     char *msg, *p;
  172.     char *tmp_format;
  173.     int    i;
  174.  
  175.     /* copy input format string */
  176.     tmp_format = emalloct((unsigned) strlen(in_format)+1, "errmsg-tmp");
  177.     strcpy(tmp_format, in_format);
  178.  
  179.     /* initialize msg to empty string */
  180.     msg = emalloct(1, "errmsg-1"); 
  181.     *msg = '\0';
  182.  
  183.     for (i = 0; i < nstrings; i++) {
  184.         p = strchr(tmp_format, '%');
  185.         if (p == 0) break;
  186.         *p = '\0';
  187.         if (p != tmp_format)
  188.             msg = strjoin(msg, tmp_format);
  189.         msg = strjoin(msg, strings[i]);
  190.         tmp_format = ++p;
  191.     }
  192.     if (tmp_format != '\0' )
  193.         msg = strjoin(msg, tmp_format);
  194.     if (p == 0) {
  195.         printf("error in proc insert, too few %c's\n", '%');
  196.     }
  197.     return(msg);
  198. }
  199.  
  200. /*
  201.  * Following are variations of pass1_error that call the appropriate
  202.  * errmsg_ routine.
  203.  * The original (simple case) pass1_error is still in 4c.c
  204.  */
  205.  
  206. void pass1_error_id(char *msg, Symbol name, char *lrm_sec, Node node)
  207.                                                         /*;pass1_error_id */
  208. {
  209.     /* This procedure is invoked when a type error which requires a special
  210.      * message is encountered in resolve1.
  211.      */
  212.  
  213.     if (cdebug2 > 3) TO_ERRFILE("AT PROC :  pass1_error_id");
  214.  
  215.     if (!noop_error) errmsg_id(msg, name, lrm_sec, node);
  216.     noop_error = TRUE;    /* To avoid cascaded errors.*/
  217. }
  218.  
  219. void pass1_error_str(char *msg, char *str, char *lrm_sec, Node node)
  220.                                                         /*;pass1_error_str */
  221. {
  222.     /* This procedure is invoked when a type error which requires a special
  223.      * message is encountered in resolve1.
  224.      */
  225.  
  226.     if (cdebug2 > 3) TO_ERRFILE("AT PROC :  pass1_error");
  227.  
  228.     if (!noop_error) errmsg_str(msg, str, lrm_sec, node);
  229.     noop_error = TRUE;    /* To avoid cascaded errors.*/
  230. }
  231.  
  232. void pass1_error_l(char *msg1, char *msg2, char *lrm_sec, Node node)
  233.                                                         /*;pass1_error_l */
  234. {
  235.     /* This procedure is invoked when a type error which requires a special
  236.      * message is encountered in resolve1.
  237.      */
  238.  
  239.     if (cdebug2 > 3) TO_ERRFILE("AT PROC :  pass1_error_l");
  240.  
  241.     if (!noop_error) errmsg_l(msg1, msg2, lrm_sec, node);
  242.     noop_error = TRUE;    /* To avoid cascaded errors.*/
  243. }
  244.  
  245. char *build_full_names(Set symbols)                    /*;build_full_names */
  246. {
  247.     /* builds a string containing the full names (scope.name) of all Symbols
  248.      * in the set 'symbols`
  249.      */
  250.  
  251.     Symbol sym;
  252.     Forset fs;
  253.     char   *name, *name_string;
  254.  
  255.     /* TBSL: this should be improved to free extra storage !! */
  256.  
  257.     name_string = strjoin("","");
  258.     if (symbols == (Set)0) return(name_string);
  259.     FORSET(sym = (Symbol), symbols, fs);
  260.         name = ORIG_NAME(SCOPE_OF(sym));
  261.         /* skip internally generated block names */
  262.         if (name[0] == '#')
  263.             name = "#BLOCK.";
  264.         else
  265.             name = strjoin(name, ".");
  266.         name = strjoin(name, ORIG_NAME(sym));
  267.         name = strjoin(name, " ");
  268.         name_string = strjoin(name_string, name);
  269.     ENDFORSET(fs);
  270.     return(name_string);
  271. }
  272.